from rest_framework_jwt.serializers import jwt_payload_handler, jwt_encode_handler
from rest_framework import serializers

class BaseSerializers(serializers.ModelSerializer):

    def login(self,attrs):
        # 手机号登入
        user = self._get_user(attrs)
        # 手动签发token
        token = self._get_token(user)
        self.context['token'] = token
        self.context['user'] = user
        return attrs

    def _get_user(self,attrs):
        pass

    def _get_token(self, user):
        payload = jwt_payload_handler(user)
        token = jwt_encode_handler(payload)
        return token

